package com.sxau.software_educational_system_backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxau.software_educational_system_backend.annotation.AdminOneOrTwo;
import com.sxau.software_educational_system_backend.annotation.AdminOnlyOne;
import com.sxau.software_educational_system_backend.annotation.AdminOnlyTwo;
import com.sxau.software_educational_system_backend.common.BaseResponse;
import com.sxau.software_educational_system_backend.common.ResultUtils;
import com.sxau.software_educational_system_backend.domain.entity.AdmitStudent;
import com.sxau.software_educational_system_backend.service.AdmitStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admit")
@RequiredArgsConstructor
@Api(tags = "录取学生信息管理接口")
public class AdmitStudentController {
    private final AdmitStudentService admitStudentService;

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询录取学生详情")
    public BaseResponse<AdmitStudent> getById(@PathVariable Integer id) {
        return ResultUtils.success(admitStudentService.getById(id));
    }

    @PostMapping("/yz")
    @ApiOperation("新增录取学生信息")
    @AdminOneOrTwo
    public BaseResponse<AdmitStudent> create(@RequestBody AdmitStudent admitStudent) {
        admitStudentService.save(admitStudent);
        return ResultUtils.success(admitStudent);
    }

    @PutMapping("/yz/{id}")
    @ApiOperation("更新录取学生信息")
    @AdminOneOrTwo
    public BaseResponse<AdmitStudent> update(@PathVariable Integer id,@RequestBody AdmitStudent admitStudent) {
        admitStudent.setId(id);
        admitStudentService.updateById(admitStudent);
        return ResultUtils.success(admitStudentService.getById(id));
    }

    @DeleteMapping("/yz/{id}")
    @ApiOperation("删除录取学生信息")
    @AdminOneOrTwo
    public BaseResponse<Void> delete(@PathVariable Integer id) {
        admitStudentService.removeById(id);
        return ResultUtils.success();
    }

    @GetMapping("/all/{student_state}")
    @ApiOperation("获取所有录取学生列表")
    public BaseResponse<List<AdmitStudent>> getByState(@PathVariable Integer student_state) {
        return ResultUtils.success(admitStudentService.getByState(student_state));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询录取学生信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10")
    })
    public BaseResponse<Page<AdmitStudent>> getPage(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<AdmitStudent> page = new Page<>(pageNo, pageSize);
        return ResultUtils.success(admitStudentService.page(page));
    }
}
